<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>网银付款</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript">
        var grid = null;
        var searchOrgTree = null;
        var addData = {};
        $(function () {
            initOrgTree();
            $("#ligergrid1").ligerGrid({
                url: '<%=path%>/infside/infBfsPay/initInfBfsPayList.do',
                method : 'get',
                columns: [
                    { display: '状态', name: 'statusNm', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '原因', name: 'message', minWidth: 150, align: 'center', enabledSort:true},
                    { display: '流水号', name: 'id', minWidth: 150, align: 'center', enabledSort:true},
                    { display: '流程编号', name: 'procInstCode', minWidth: 200, align: 'center', enabledSort:true},
                    { display: '承租人', name: 'customerName', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '支付表号', name: 'paylistCode', minWidth: 150, align: 'center', enabledSort:true},
                    { display: '项目名称', name: 'projectName', minWidth: 150, align: 'center', enabledSort:true},
                    { display: '创建时间', name: 'crtTm', minWidth: 200,render:renderDateHms, align: 'center', enabledSort:true},
                    { display: '所属事业部', name: 'orgNo', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '所属公司', name: 'provincialCompany', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '实际放款金额', name: 'payMoneyRealdou', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '收款账户', name: 'payeeCorp', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '收款账号', name: 'payeeAcc', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '收款银行', name: 'payeeBank', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '收款银行行号', name: 'payeeBankCode', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '期望付款时间', name: 'wishPayday', minWidth: 100,render:renderDate, align: 'center', enabledSort:true},
                    { display: '实际付款时间', name: 'payDate', minWidth: 100,render:renderDate, align: 'center', enabledSort:true},
                    { display: '付款金额', name: 'payMoneydou', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '付款账户', name: 'payerAccname', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '付款账号', name: 'payerAcc', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '付款银行', name: 'payerBank', minWidth: 100, align: 'center', enabledSort:true},
                    {
                        display: '操作',minWidth: 100,align: 'center',
                        render: function (rowdata, rowindex, value){
                            var h1='<sys:funcAuth resCd="sendInfo200520151001101"><span style="color:#C9C9C9;">发送</span></sys:funcAuth>';
                            if(rowdata.status=="sendWait" || rowdata.status=="sendFailure" || rowdata.status=="payFailure" || rowdata.status=="payCancel"){
                                //待发送或者发送失败
                                h1='<sys:funcAuth resCd="sendInfo200520151001101"><a href="javascript:void(0);" onclick="manualSendPay(\''+rowdata.id+'\')">发送</a></sys:funcAuth>';
                            }
                            var h2 = ' <sys:funcAuth resCd="mdfshow1805"><a href="javascript:void(0);" onclick="modifyPay(\''+rowdata.id+'\')">修改</a></sys:funcAuth>';
                            var h3 = ' <sys:funcAuth resCd="payFailure200520151001103"><a href="javascript:void(0);" onclick="payFailure(\''+rowdata.id+'\')">付款失败</a></sys:funcAuth>';
                            return h1 + h2 + h3;
                        }
                    }
                ],
                pageSize:10,
                root:'rows',
                record:'total',
                hideLoadButton : true,
                width: '100%',
                height:380,
                heightDiff:-2,
                //checkbox:true,
                rownumbers:true
            });
            grid = liger.get("ligergrid1");
            $("#searchBar").ligerForm();
            $("#searchBtn").click(function(event) {
                var form = new liger.get("searchBar");
                var data = form.getData();
                console.log(data);
                for (name in data){
                    grid.setParm(name,data[name]);
                };
                grid.reload();
            });
            $("#clearBtn").click(function(event) {
                clearLigerForm("searchBar");
            });

            $("#saveChange_Btn").click(function (event) {
                var form = liger.get("change_form");
                if (!form.valid()) {
                    $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                    return false; //验证不通过，不执行以下代码
                }
                var data = form.getData();
                $.ligerDialog.hide();
                //以下应该有一段Ajax交互
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: data,
                    url: '<%=path%>/infside/infBfsPay/modify.do?id=' + addData.id,
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            bankHeadQ = null;
                            $("#resetBtn").click();
//                        $("#searchBtn").click();
                            grid.reload($('.pcontrol input', grid.toolbar).val());
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });
        //发送资金
        function manualSendPay(_ibfspayId){
            $.ligerDialog.confirm("是否确认发送?", function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:'ibfspayId='+_ibfspayId,
                    url: '<%=path%>/infside/infBfsPay/manualSendPay.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        
        //付款失败
        function payFailure(_ibfspayId){
            $.ligerDialog.confirm("是否确认此操作?", function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:'ibfspayId='+_ibfspayId,
                    url: '<%=path%>/infside/infBfsPay/payFailure.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        
        //修改
        function modifyPay(id) {
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: '<%=path%>/infside/infBfsPay/getById.do?id=' + id,
                success: function (msg) {
                    if (msg.success == 1) {
                        //$.ligerDialog.success(msg.info)
                        openChange();//弹出修改框
                        setData(msg.data);//设置数据
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        }
        function openChange() {
            $.ligerDialog.open({
                width: 400,
                top: 100,
                title: '修改付款信息',
                target: $("#change_Html"),
                onHideDialog: function () {
                    clearLigerForm("change_form");
                }
            });
            $("#change_form").ligerForm({validate: true});
        }
        //设置页面数据
        function setData(data) {
            var form = new liger.get("change_form");
            addData.id = data.id;
            form.setData({
            	payerAcc: data.payerAcc,
                payMoneyRealdou: data.payMoneyRealdou,
                payDate: data.payDate
            });
        }
        //初始化组织架构
        function initOrgTree(){
            searchOrgTree = $("#provincialCompany").ligerComboBox({
                selectBoxWidth: 240,
                selectBoxHeight: 150,
                valueField:'orgCd',
                textField:'orgDispNm',
                //限制只能选叶节点，父节点不能点击
                treeLeafOnly: false,
                tree: {
                    ajaxType: 'get',
                    idFieldName:'orgCd',
                    textFieldName: 'orgDispNm',
                    checkbox: false,
                    parentIcon: "none",
                    childIcon: "none",
                },
                onSelected: function (){}
            });
            $.ajax({
                type: 'get',
                dataType:'json',
                data: "",
                url: '<%=path%>/infside/infBfsPay/searchOrgTree.do',
                success:function(msg){
                    if(msg.success == 1){
                        searchOrgTree.treeManager.setData(msg.data);
                        searchOrgTree.clear();
                    }else{
                        $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                    }
                }
            });

        }
        //格式化时间
        function renderDate(rowdata, index, value){
            var dateStr = "";
            if(null != value){
                var date = new Date(value);
                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
            }
            return dateStr;
        }
        //格式化时间
        function renderDateHms(rowdata, index, value){
            var dateStr = "";
            if(null != value){
                var date = new Date(value);
                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
            }
            return dateStr;
        }
        //导出
        function exportInfBfsPayExcel(){
            var form = liger.get("searchBar");
            var data = form.getData();
            var req="format=xls";
            for (name in data) {
                for (name in data) {
                    if(data[name]){
                        req+="&"+name+"="+data[name];
                    }
                }
            }
            window.location.href="<%=path%>/infside/infBfsPay/exportInfBfsPayExcel.do?"+req;
        }
    </script>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">状态</div>
                    <div class="field">
                        <select name="status"  id="status"  disabled="disabled">
                            <option value="  " selected="selected">--请选择--</option>
                            <c:forEach items="${statuslist}" var="opt">
                                <option value="${opt.key}">${opt.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">流程编号</div>
                    <div class="field">
                        <input name="procInstCode" id="procInstCode" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支付表编号</div>
                    <div class="field">
                        <input name="paylistCode" id="paylistCode" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">承租人</div>
                    <div class="field">
                        <input name="customerName" id="customerName" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">项目名称</div>
                    <div class="field">
                        <input name="projectName" id="projectName" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">所属公司</div>
                    <div class="field">
                        <input name="provincialCompany" id="provincialCompany" type="text" value="" placeholder="请选择"  ltype="combobox">
                    </div>
                    <div style="display: none">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">创建时间(起)</div>
                    <div class="field">
                        <input name="beginCreateTime" id="beginCreateTime" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">创建时间(止)</div>
                    <div class="field">
                        <input name="endCreateTime" id="endCreateTime" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">付款时间(起)</div>
                    <div class="field">
                        <input name="beginPayTime" id="beginPayTime" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">付款时间(止)</div>
                    <div class="field">
                        <input name="endPayTime" id="endPayTime" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
                    <sys:funcAuth resCd="exportInfo200520151001102">
                        <span class="sq-button sq-button-hasicon" onclick="exportInfBfsPayExcel()"><i class="sqBtnIco_21"></i>导出</span>
                    </sys:funcAuth>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
<span>
    说明：
    <br>
    1、发送成功:此付款申请已经成功发送拜特资金管理系统。
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    2、发送失败:此付款申请没有成功发送拜特资金管理系统，需要重发。
    <br>
    3、付款修改:拜特资金管理系统将此付款申请打回，需要修改重发或者终止业务。 4、待发送:付款申请修改过后生成的新记录。
    <br>
    5、付款作废:拜特资金管理系统将此付款申请作废，需要修改重发或者终止业务。 6、已作废:此付款申请已经手工作废，对应放款流程已经终止。
    <br>
    7、付款成功:此付款申请已经通过银企直联成功付款。

</span>

<!-- 修改风控管理信息弹出框 -->
<div id="change_Html" style="display:none">
    <form id="change_form">
        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_100">
                <div class="label">付款账号</div>
                <div class="field">
                    <input name="payerAcc" id="payerAcc" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">实际放款金额</div>
                <div class="field">
                    <input name="payMoneyRealdou" id="payMoneyRealdou" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">实际付款时间</div>
                <div class="field">
                    <input name="payDate" id="payDate" type="text" class="ui-datepicker" ligerui="{showTime:true}" value="">
                    <input id="resetBtn3" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="saveChange_Btn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_10"></i>保存</span>
        </div>
    </form>
</div>
</body>
</html>
